const {
    tokenDecode
} = require("../utils/JWT")
const adminModel = require("../db/model/adminModel")
module.exports =async (req, res, next) => {
    const {
        token
    } = req.headers
    
    const tokenResult = tokenDecode(token, "nishilaoliu")
    //解码token
    if (tokenResult.code === 0) {
        return res.send({
            code: 20000,
            msg: "权限控制解码失败",
            data: null
        })
    }
    const adminName=tokenResult.adminName
    const findResult =await adminModel.findOne({adminName})
    // console.log(findResult);
    //确定登录状态
    if (!findResult||findResult.state === 0) {
        return res.send({
            code: 20000,
            msg: "权限校验中用户登录状态过期",
            data: null
        })
    }

    next()

}